$("input[type='text'],textarea").each(function(){//自动填充Input框
	addInput($(this));
}).focus(function(){
	if($(this).next().attr('type') == 'password'){
		$(this).hide();
		$(this).next().show().focus().blur(function(){
			if(!$(this).val()){
				$(this).hide().prev().show();
			}
		});
	}else if($(this).hasClass('default')){
		$(this).removeClass('default').val('');
	}
}).blur(function(){
	addInput($(this));
});

function addInput($that){
	var title = $that.attr('title');
	if(title && !$that.val()){
		$that.addClass('default').val(title);
	}
}

function flToggle(that){//显示或隐藏浮动选择项
	if($(that).hasClass('show')){
		$(that).removeClass('show');
	}else{
		$(that).addClass('show');
	}
	var $that = $(that).next();
	$that.toggle();
}

function showHide(that,obj){//显示隐藏内容
	if($(that).hasClass('show')){
		$(that).removeClass('show');
	}else{
		$(that).addClass('show');
	}
	
	if(typeof obj == 'object'){
		obj.toggle();
	}else if(typeof obj == 'string'){
		$('.'+obj).toggle();
	}
}
//网才直聘账号显示密码
function showPwd_input(that,pwd){
	var $that = $(that);
	var $box = $that.parent();
	var $ipt = $box.find("input[type='text']");
	var $pwd = $box.find("input[type='password']");
	$box.find('input').off('focus').off('blur');
	
	if($ipt[0].style.display == 'none'){
		$that.addClass("iconmmon").removeClass("iconmm");
		$pwd.hide();
		$ipt.attr('id',pwd);
		$pwd.attr('id','');
		$ipt.show().val($pwd.val());
	}else if($pwd[0].style.display == 'none'){
		$that.addClass("iconmm").removeClass("iconmmon");
		if(!$ipt.val() || ($ipt.val()==$ipt.attr('title'))){
			$ipt.val('');
		}
		$ipt.attr('id','');
		$pwd.attr('id',pwd);
		$ipt.hide();
		$pwd.show().val($ipt.val());
	}
}

function showPwd(that,pwd){//显示密码
	var $that = $(that);
	var $box = $that.parent();
	var $ipt = $box.find("input[type='text']");
	var $pwd = $box.find("input[type='password']");
	
	$box.find('input').off('focus').off('blur');
	
	if($ipt[0].style.display == 'none'){
		$that.html('隐藏密码').attr('title','ipt');
		$pwd.hide();
		$ipt.attr('id',pwd);
		$pwd.attr('id','');
		$ipt.show().val($pwd.val());
	}else if($pwd[0].style.display == 'none'){
		$that.html('显示密码').attr('title','pwd');
		if(!$ipt.val() || ($ipt.val()==$ipt.attr('title'))){
			$ipt.val('');
		}
		$ipt.attr('id','');
		$pwd.attr('id',pwd);
		$ipt.hide();
		$pwd.show().val($ipt.val());
	}
}


function setAuto(that){//登录页，自动登录按钮；隐私设置
	var $that = $(that).find('font');
	if($that.hasClass('not')){
		$that.removeClass('not');
	}else{
		$that.addClass('not');
	}
}

function pop(msg,mtype,but1,but2,fun1,fun2){//弹出层
	//msg:文本信息
	//mtype:弹层类型	0:文字靠左显示		1:文字居中显示
	//but1:按钮一文字
	//but2:按钮二文字
	//fun1:按钮一方法
	//fun2:按钮二方法
	
	var top = document.body.scrollTop || document.documentElement.scrollTop;
	var h = document.body.scrollHeight > windowH ? document.body.scrollHeight : windowH;
	
	mtype	= mtype ? mtype : 0;
	
	if($('#pop')[0]){
		var $text = $('#pop .text');
		var butInfo = but1 ? "<span onclick='"+fun1+"'>"+but1+"</span>" : '';
		if(mtype){
			if(!$text.hasClass('center')){
				$text.addClass('center');
			}
		}else{
			$text.removeClass('center');
		}

		$('#pop .text').html(msg);

		if(but2){
			butInfo += "<span onclick="+fun2+">"+but2+"</span>";
		}
		
		if(butInfo){
			if($('#pop .op')[0]){
				$('#pop .op').html(butInfo);
			}else{
				$('#pop .cn').append("<div class='op'>"+butInfo+"</div>");
			}
		}else{
			$('#pop .op').remove();
		}
		
		if(arguments.length > 2){
			$('#pop .cn').removeClass('c2');
			$('#pop .close').remove();
		}
		
	}else{
		var className = "text";
		var butInfo = but1 ? "<span onclick="+fun1+">"+but1+"</span>" : '';
		if(mtype){
			className = "text center";
		}
		if(but2){
			butInfo += "<span onclick="+fun2+">"+but2+"</span>";
		}
		
		var htm  = "<section id='pop'>";
		if(arguments.length <= 2){
			htm += "<div class='cn c2'>";
			htm += "<span class='close' onclick='popclose()' id='close_btn'></span>";
		}else{
			htm += "<div class='cn'>";
		}
			htm += "<p class='"+className+"'>"+msg+"</p>";
		if(butInfo){
			htm += "<div class='op'>";
			htm += butInfo;
			htm += "</div>";
		}
			htm += "</div>";
			htm += "</section>";
			
		if(!$('#shadow')[0]){
			htm += "<div id='shadow'></div>";
		}
		
		$('body').append(htm);
	}
	
	var tp = $('#pop').height();
	var hb = document.documentElement.clientHeight;
	tp = (hb-tp)/2;
	tp = tp >=0 ? tp : 0;
	tp += top;
	
	$('#shadow').height(h);
	$('#pop').css('top',tp);
	
	$('#pop,#shadow').show();
}
function popshow(name){//特殊弹出层
	if(!$('#shadow')[0]){
		$('body').append("<div class='shadow'></div>");
	}
	
	name = '.'+name;
	var top = document.body.scrollTop || document.documentElement.scrollTop;
	var h = $('body').height();
	var tp = $(name).height();
	var hb = document.documentElement.clientHeight;
	
	tp = (hb-tp)/2;
	tp = tp >=0 ? tp : 0;
	tp += top;
	
	$('#shadow').height(h);
	$(name).css('top',tp);

	$('#shadow,'+name).show();
}

function popclose(){//弹出层关闭
	$('#pop,.pop,#shadow').hide();
}

/*---添加到桌面---*/
function addToHome(){
	var ua = window.navigator.userAgent;
	var nav = window.navigator;
	
	var isOther = (/ucbrowser|ucweb|qq/i).test(ua);
	if(isOther){
		return 0;
	}
	
	var isIOS = (/iphone|ipod|ipad/i).test(ua);
	
	if(isIOS && window.localStorage){
		if((/os 7_|os 8_/i).test(ua)){
			var img = "<img width='19' height='27' src='http://img01.51jobcdn.com/im/jc/image/stt_icon.png' alt='' />";
		}else if((/os 6_/i).test(ua)){
			var img = "<img width='25' height='25' src='http://img01.51jobcdn.com/im/jc/image/stt_icon2.png' alt='' />";
		}else{
			return 0;
		}
		
		var htm = "<div id='STT' class='bb'><div class='scn'><img class='cl' onclick='addToHome_close()' width='14' height='14' src='http://img01.51jobcdn.com/im/jc/image/close.png' alt='' /><p class='p1'><img width='60' height='60' src='http://img01.51jobcdn.com/im/mobile/m/logo_114.png' alt='' /><br />无忧招聘</p><p class='p2'>点击"+img+",可以将图标添加到桌面哟~</p></div></div>";
		
		if(!localStorage.addToHome_tm){
			localStorage.addToHome_tm = 0;
		}
		
		var s_tm = localStorage.addToHome_tm;

		if(s_tm == 0){
			$('body').append(htm);
			setTimeout(function(){
				$('#STT').css({'bottom':0,'opacity':1});
			},100);
		}
	}
}

function addToHome_close(){
	localStorage.addToHome_tm = 1;
	$('#STT').remove();
}

function getScrollTop(){
	var top = $('body').scrollTop();
	markST = 0;
	if(top){
		markST = 1;
		return top;
	}else if(document.documentElement.scrollTop){
		markST = 2;
		return document.documentElement.scrollTop;
	}else{
		markST = 3;
		return 0;
	}
}

function setScrollTop(){
	var val = arguments[0] || pLoadTop;
	if(markST == 1){
		$('body').scrollTop(val);
	}else if(markST == 2){
		document.documentElement.scrollTop = val;
	}else if(markST == 3){
		$('body').scrollTop(val);
		document.documentElement.scrollTop = val;
	}
}

function pLoad(page,that){//页面加载
	pLoadTop = getScrollTop() || 0;
	
	var $pobj = $('#'+page);
	var $that = $(that).parents('.pgbox');
	
	
	if($pobj[0]){
		$('.pgbox').hide();
		setScrollTop(0);
		$pobj.show();
	}else{
		var id = $that.attr('id');
		var h = $('body').height();
		var t = document.body.scrollTop || document.documentElement.scrollTop;
		t = (window.screen.height-120)/2+t;
		
		if(!$('#shadow')[0]){
			$('body').append("<div id='shadow' style='height:"+h+"px'></div>");
		}else{
			$('#shadow').height(h);
		}
		if(!$('#loading')[0]){
			$('body').append("<div id='loading' style='top:"+t+"px'><span>Loading<em>...</em></span></div>");
		}else{
			
		}
		$('#shadow,#loading').show();
		
		$.ajax({
			url			: page+'.php',
			timeout		: 1000,
			success		: function(data){
				var htm = "<div id='"+page+"' class='pglox pgbox' title='"+id+"' style='z-index:20'>"+data+"</div>";
				$('body').append(htm);
				setTimeout(function(){
					$('body').scrollTop(0);
					$('.pgbox').hide();
					$that.hide();
					$('#'+page).show();
					$('#shadow,#loading').hide();
				},500);
				
			},
			error		: function(xhr,errorType,error){
				if(errorType == 'timeout'){
					alert('服务器等待超时！');
				}else if(errorType == 'error' && error == 'Not Found'){
					alert('未找到服务器文件！');
				}
				$('#shadow,#loading').hide();
			}
		});
	}
}

function timeClock(id,num){
	var that = document.getElementById(id);
	var num = num ? num : 60;
	var fID = setInterval(setBut,1000);
	
	that.setAttribute('class','anfsyzm_gray');
	
	function setBut(){
		if(num>0){
			that.innerHTML = num+'秒后重新发送';
			num--;
		}else{
			that.innerHTML = '重新发送验证码';
			that.setAttribute('class','anfsyzm dh_sendphonecode');
			clearInterval(fID);
			$(".anfsyzm").bind("click",dh_sendphonecode);
		}
	}
}

$('.back,.com_back,.savefunc').bind('click',function(){//返回
	if(!$(this).attr('href')){
		var $pName = $(this).parents('.pgbox');
		var $that = $pName.attr('title');
		$that = $('#'+$that);
		$pName.css('z-index','7').hide();
		$that.show();
		
		setScrollTop();
	}
});

$('.cinfo').each(function(){//公司介绍，显示更多
	if($(this).find('p').height() > 120){
		$(this).parent().find('.more').css('display','inline-block');
	}
});

$('.more').click(function(){//公司介绍，显示更多
	var $that = $(this).parents('.cmbox').find('.cinfo');
	if($that.height() > 120){
		$(this).html('查看全部').removeClass('mk');
		$that.css('max-height',120);
	}else{
		$(this).html('收起内容').addClass('mk');
		$that.css('max-height','none');
	}
});

$('.i_add').click(function(){//招聘人数增加
	var $that = $(this).parent().find('input');
	var num = $that.val() ? $that.val() : 0;
	var num = parseInt(num);
	if(num == '999'){
		return false;
	}
	num++;
	$that.val(num);
});

$('.i_sub').click(function(){//招聘人数减少
	var $that = $(this).parent().find('input');
	var num = $that.val() ? $that.val() : 0;
	var num = parseInt(num);
	
	if(num > 1){
		num--;
		$that.val(num);
	}
});
/*
$('.num_add').click(function(){//无忧竞价出价职位数增加
	var $that = $(this).parent().find('input');
	var num = $that.val() ? $that.val() : 0;
	var num = parseInt(num);
	if(num == '999'){
		return false;
	}
	num++;
	$that.val(num);
});

$('.num_sub').click(function(){//无忧竞价出价职位数减少
	var $that = $(this).parent().find('input');
	var num = $that.val() ? $that.val() : 0;
	var num = parseInt(num);
	
	if(num > 1){
		num--;
		$that.val(num);
	}
});
*/
$('.slet select').change(function(){//下拉框取值
	var v = '';
	$(this).find('option').each(function(){
		if($(this).attr('selected') == true){
			v = $(this).html();
			return false;
		}
	});
	$(this).siblings().html(v);
}); 
$('.bb select').change(function(){//下拉框取值
	var v = '';
	$(this).find('option').each(function(){
		if($(this).attr('selected') == true){
			v = $(this).html();
			return false;
		}
	});
	$(this).siblings().html(v);
}); 

$(function(){
	windowH = window.innerHeight;//浏览器显示区域大小
});


/*
 *
 * 页面链接，临时
 * 
 */
function jmp(name){
	window.location.href = name+'.php';
}


function tpimg(){
	window.location.href = '图片展示.php';
}

function back(){
	window.history.go(-1);
}




/*---图片展示---*/
function fSwiper(n,c){
	var num = swiperImg.length;
	var boxH = windowH - 58;
	document.body.scrollTop = 0;
	
	if($('#js_swiper')[0]){
		mySwiper.swipeTo(n,0);
		$('#shadow,#js_swiper').show();
	}else{
		var htm  = "<div id='js_swiper'>";
			htm += "<p class='pt'>";
		for(var i=0;i<num;i++){
			htm += "<span></span>";
		}
			htm += "<em onclick='swiperClose()'>关闭</em>";
			htm += "</p>";
			htm += "<div class='swiper_box'>";
			htm += "<span class='prev' onclick='mySwiper.swipePrev()' style='top:"+(boxH/2-30)+"px'></span><span class='next' onclick='mySwiper.swipeNext()' style='top:"+(boxH/2-30)+"px'></span>";
			htm += "<div class='swiper-container' style='height:"+boxH+"px'>";
			htm += "<div class='swiper-wrapper'>";
		for(var i=0;i<num;i++){
			htm += "<div class='swiper-slide' style='color:red;height:"+boxH+"px'>";
			htm += "<img width='40' height='40' style='margin-top:"+(boxH/2-50)+"px' src='http://img01.51jobcdn.com/im/iehire/image/loading.gif' alt='loading' />";
			htm += "<span style='display:none' title='"+swiperImg[i]+"'></span>";
			htm += "</div>";
		}
			htm += "</div>";
			htm += "</div>";
			htm += "</div>";
			htm += "</div>";
			
		if(!$('#shadow')[0]){
			htm += "<div id='shadow'></div>";
		}
		
		$('body').append(htm);
		
		mySwiper = $('.swiper-container').swiper({			
			mode:'horizontal',
			loop: true,
			onSlideChangeStart: function(swiper){
				var that = mySwiper.activeSlide();
				var index = mySwiper.activeIndex;
				
				if(index==0){
					index = num-1;
				}else if(index>num){
					index = 0;
				}else{
					index--;
				}
				$('#js_swiper .pt span').removeClass('mk').eq(index).addClass('mk');
				
				loadImg(that);
		    }
		});
		 if(c=='' || c==1){
		 	$('#js_swiper p span').css('display','none');
		 	$('#js_swiper .swiper_box span').css('display','none');
		 }

		fSwiper(n);
	}
}

function loadImg(that){
	var $that = $(that);
	var $img = $that.find('img');
	
	function setBox(img){
		if(img.width<=300){
			var h = img.height;
		}else{
			var h = parseInt(img.height*300/img.width);
		}
		
		if(h > windowH){
			$that.height(h);
			$('.swiper-container').height(h);
		}
	}
	
	if($img.attr('alt') != 'loading'){
		setBox($img[0]);
		return 0;
	}
	
	var src = $that.find('span').attr('title');
	var img = new Image();
	img.src = src;
	
	img.onload = function(){
		$img.removeAttr('width').removeAttr('height').removeAttr('style').attr('src',src).attr('alt','');
		
		setBox(img);
	}
}

function swiperClose(){
	$('#shadow,#js_swiper').hide();
}

var wSave = {//表单数据存储
	name	: '',
	time	: ''
};
wSave.ini = function(name){
	if(window.sessionStorage){
		wSave.name = 'wSave_'+name;
		
		if(sessionStorage[wSave.name]){
			wSave.get();
		}
		wSave.set();
	}
};
wSave.set = function(){
	var result = {};
	var el = {
		'input' 	: $("input[type='text']"),
		'select'	: $("select"),
		'textarea'	: $("textarea")
	}
	for(k in el){
		result[k] = {};
		el[k].each(function(){
			var name = $(this).attr('name');
			var title = $(this).attr('title');
			var value = $(this).val();
			if(name && title!=value){
				result[k][name] = $(this).val();
			}
		});
	}
	
	result = JSON.stringify(result) || '';
	sessionStorage.setItem(wSave.name,result);
};
wSave.get = function(){
	var result = {};
	console.log(sessionStorage[wSave.name])
};